<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="订单号" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="请输入" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="房源" prop="premisesAddress">
        <el-input v-model="queryParams.premisesAddress" placeholder="请输入" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="住客名称" prop="lesseeName">
        <el-input v-model="queryParams.lesseeName" placeholder="请输入" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="入离时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="orderState">
        <el-select v-model="queryParams.orderState" placeholder="" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.order_short_relet_state" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb20">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--        >新建-->
<!--        </el-button-->
<!--        >-->
<!--      </el-col>-->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="roomList" @selection-change="handleSelectionChange" ref="table">
      <el-table-column label="续租单号" prop="orderId" :show-overflow-tooltip="true" />
      <el-table-column label="关联订单" prop="linkedOrderId" :show-overflow-tooltip="true" />
      <el-table-column label="房源" prop="premisesAddress" :show-overflow-tooltip="true" />
      <el-table-column label="住客信息" prop="" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <div>{{ scope.row.orderLessee.lesseeName }}</div>
          <div>{{ scope.row.orderLessee.phone }}</div>
        </template>
      </el-table-column>

      <el-table-column label="入离日期" prop="checkInTime">
        <template slot-scope="scope">
          <div>入：{{ scope.row.checkInTime | formatDate("YYYY-MM-DD") }}</div>
          <div>离：{{ scope.row.checkOutTime | formatDate("YYYY-MM-DD") }}</div>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="orderState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_short_relet_state" :value="scope.row.orderState" />
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { reletList } from "@/api/order/continue";
export default {
  name: "reletList",
  dicts: ["order_state", "order_source", "order_short_relet_state"],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      roomList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 当前选择
      current: "all",
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],

      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        premisesAddress: undefined,
        orderSource: undefined,
        orderState: undefined,
        checkInTime: "",
        checkOutTime: "",
      },
      countHouseList: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        roomNumber: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
      detailDialogVisible: false,
      orderId: "",
      openChangeHouse: false,
      openEdit: false,
      orderInfo: {},
      addDialogVisible: false, //新建弹窗，
      openmembershipRegistration: false,
      idEdit: false, //是否编辑成员
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    handleMembers(row) {
      this.isEdit = false;
      this.orderInfo = row;
      this.openmembershipRegistration = true;
    },
    editMembers(row) {
      this.isEdit = true;
      this.orderInfo = row;
      this.openmembershipRegistration = true;
    },
    dialogClose() {
      this.openChangeHouse = false;
      this.openEdit = false;
      this.openmembershipRegistration = false;
      this.getList();
    },
    stateHandel(i) {
      let orderState = this.countHouseList[i].value;
      this.queryParams.orderState = orderState;
      this.handleQuery();
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      this.queryParams.checkInTime = this.dateRange[0];
      this.queryParams.checkOutTime = this.dateRange[1];
      reletList(this.queryParams, this.dateRange).then((response) => {
        this.roomList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.orderId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.queryParams.orderIds = this.ids;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.orderId = "";
      this.addDialogVisible = true;
    },
    // 详情操作
    handleDetail(row) {
      this.orderId = row.orderId;
      this.detailDialogVisible = true;
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.orderInfo = row;
      this.openEdit = true;
    },
    //换房操作
    handleChangeHouse(row) {
      this.orderInfo = row;
      this.openChangeHouse = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "enterprise/order/order/export",
        {
          ...this.queryParams,
        },
        `订单_${new Date().getTime()}.xlsx`
      );
    },
    //请空选择项
    clearSelect() {
      this.$refs.table.clearSelection();
    },
  },
};
</script>
<style lang="scss" scoped>
.title {
  font-size: 14px;
  font-weight: 500;
  color: #666;
}

.total {
  font-size: 18px;
  font-weight: 500;
  color: #333;
  margin-top: 6px;
}

.left-border {
  border-left: 1px solid #999;
}

.right-border {
  border-right: 1px solid #999;
}

.info {
  padding: 10px 15px;
  margin: 15px 0;
  background: #e6f7ff;
  color: #1890ff;

  span {
    color: #565c5f;
  }

  .clear {
    margin-left: 20px;
    cursor: pointer;
  }
}
</style>
